namespace ASPNET.StarterKit.IssueTracker
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using ASPNET.StarterKit.IssueTracker.UserInterfaceLayer;
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class History : UserControl, IIssueTab
    {
        [AccessedThroughProperty("grdHistory")]
        private DataGrid _grdHistory;
        private int _IssueId;
        private object designerPlaceholderDeclaration;

        public History()
        {
            base.PreRender += new EventHandler(this.Page_PreRender1);
            base.Init += new EventHandler(this.Page_Init);
            this._IssueId = 0;
        }

        public void BindHistory()
        {
            this.grdHistory.DataSource = IssueHistory.GetIssueHistoryByIssueId(this._IssueId);
            this.grdHistory.DataBind();
        }

        public void grdHistoryItemDataBound(object s, DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) | (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                IssueHistory currentHistory = (IssueHistory) e.Item.DataItem;
                Label lblCreatorDisplayName = (Label) e.Item.FindControl("lblCreatorDisplayName");
                lblCreatorDisplayName.Text = currentHistory.CreatorDisplayName;
                Label lblDateCreated = (Label) e.Item.FindControl("lblDateCreated");
                lblDateCreated.Text = currentHistory.DateCreated.ToString("f");
            }
        }

        public void Initialize()
        {
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_PreRender1(object sender, EventArgs e)
        {
            this.BindHistory();
        }

        int ASPNET.StarterKit.IssueTracker.UserInterfaceLayer.IIssueTab.IssueId
        {
            get
            {
                return this._IssueId;
            }
            set
            {
                this._IssueId = value;
            }
        }

        protected virtual DataGrid grdHistory
        {
            get
            {
                return this._grdHistory;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._grdHistory != null)
                {
                    this._grdHistory.ItemDataBound -= new DataGridItemEventHandler(this.grdHistoryItemDataBound);
                }
                this._grdHistory = value;
                if (this._grdHistory != null)
                {
                    this._grdHistory.ItemDataBound += new DataGridItemEventHandler(this.grdHistoryItemDataBound);
                }
            }
        }

        public int IssueId
        {
            get
            {
                return this._IssueId;
            }
            set
            {
                this._IssueId = value;
            }
        }
    }
}

